/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.jellyfishumbrella.GL;

import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.util.glu.GLU.*;

import java.io.IOException;
import java.util.logging.FileHandler;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.lwjgl.LWJGLException;
import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import java.awt.geom.*;
import org.lwjgl.util.vector.*;

import com.jellyfishumbrella.GameLogic;

import java.util.concurrent.*;

/**
 * 
 * @author 500441547
 */
public class Camera {
	public static float			FOV				= 50.0f;
	public static boolean		keepCentered	= false;
	public static final float	SPEED			= 3.0f * GameLogic.GL_SCALE;
	public static final float	CREEP_SPEED		= 0.125f;
	public static boolean		CREEP			= false;

	public Vector3f				_pos;
	// store POS as x,y,z -- so altitude comes second.
	public Vector3f				_vel;
	public Vector3f				_rot;
	public boolean				isFlying		= false;
	public static boolean		inNewHex		= false;
	public static boolean		inNewField		= false;

	public static float[]		viewMatrix		= { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f };

	public Camera() {
		super();
		_pos = new Vector3f(0.0f, 50.0f, 90.0f);
		_vel = new Vector3f(0.0f, 0.0f, 0.0f);
		_rot = new Vector3f(35.0f, 0.0f, 0.0f);
	}

	public void render() {
		float COLS = 16.0f;
		float ROWS = 16.0f;
		float STACK = 64.0f;

		glRotatef(_rot.x, 1.0f, 0.0f, 0.0f);
		glRotatef(_rot.y, 0.0f, 1.0f, 0.0f);
		glRotatef(_rot.z, 0.0f, 0.0f, 1.0f);
		glTranslatef(-_pos.x, -_pos.y, -_pos.z);
	}

	public void update() {}

	public void moveForward() {
		float speed;
		if (CREEP) {
			speed = CREEP_SPEED;
		} else {
			speed = SPEED;
		}
		float xrotrad, yrotrad, yrotradY, yrotradZ;
		xrotrad = (float) Math.PI * ((_rot.x) / 180.0f);
		yrotrad = (float) Math.PI * ((_rot.y) / 180.0f);
		// yrotradY = (float)Math.PI * ((_rot.y+30.0f) / 180.0f);
		// yrotradZ = (float)Math.PI * ((_rot.y-30.0f) / 180.0f);
		// _hexCoords.x += speed * (float)(Math.sin(yrotrad));
		// _hexCoords.y += speed * (float)(Math.cos(yrotradY));
		// _hexCoords.z -= speed * (float)(Math.cos(yrotradZ));
		_pos.x += SPEED * (float) (Math.sin(yrotrad));
		if (isFlying) {
			_pos.y -= SPEED * (float) (Math.sin(xrotrad));
		}
		_pos.z -= SPEED * (float) (Math.cos(yrotrad));
	}

	public void moveBackward() {
		float speed;
		if (CREEP) {
			speed = CREEP_SPEED;
		} else {
			speed = SPEED;
		}
		float xrotrad, yrotrad, yrotradY, yrotradZ;
		xrotrad = (float) Math.PI * ((_rot.x) / 180.0f);
		yrotrad = (float) Math.PI * ((_rot.y) / 180.0f);
		// yrotradY = (float)Math.PI * ((_rot.y+30.0f) / 180.0f);
		// yrotradZ = (float)Math.PI * ((_rot.y-30.0f) / 180.0f);
		// _hexCoords.x -= speed * (float)(Math.sin(yrotrad));
		// _hexCoords.y -= speed * (float)(Math.cos(yrotradY));
		// _hexCoords.z += speed* (float)(Math.cos(yrotradZ));
		_pos.x -= SPEED * (float) (Math.sin(yrotrad));
		if (isFlying) {
			_pos.y += SPEED * (float) (Math.sin(xrotrad));
		}
		_pos.z += SPEED * (float) (Math.cos(yrotrad));
	}

	public void moveLeft() {
		float speed;
		if (CREEP) {
			speed = CREEP_SPEED;
		} else {
			speed = SPEED;
		}
		float yrotrad, yrotradY, yrotradZ;
		yrotrad = (float) Math.PI * (_rot.y / 180.0f);
		// yrotradY = (float)Math.PI * ((_rot.y+60.0f) / 180.0f);
		// yrotradZ = (float)Math.PI * ((_rot.y-60.0f) / 180.0f);
		// _hexCoords.x -= speed * (float)(Math.cos(yrotrad));
		// _hexCoords.y -= speed * (float)(Math.cos(yrotradY));
		// _hexCoords.z -= speed * (float)(Math.cos(yrotradZ));
		_pos.x -= SPEED * (float) (Math.cos(yrotrad));// * 0.5f;
		_pos.z -= SPEED * (float) (Math.sin(yrotrad));// * 0.5f;
	}

	public void moveRight() {
		float speed;
		if (CREEP) {
			speed = CREEP_SPEED;
		} else {
			speed = SPEED;
		}
		float yrotrad, yrotradY, yrotradZ;
		yrotrad = (float) Math.PI * (_rot.y / 180.0f);
		// yrotradY = (float)Math.PI * ((_rot.y+60.0f) / 180.0f);
		// yrotradZ = (float)Math.PI * ((_rot.y-60.0f) / 180.0f);
		// _hexCoords.x += speed * (float)(Math.cos(yrotrad));
		// _hexCoords.y += speed * (float)(Math.cos(yrotradY));
		// _hexCoords.z += speed * (float)(Math.cos(yrotradZ));
		_pos.x += SPEED * (float) (Math.cos(yrotrad));// * 0.5f;
		_pos.z += SPEED * (float) (Math.sin(yrotrad));// * 0.5f;
	}

	public void moveUp() {
		float speed;
		if (CREEP) {
			speed = CREEP_SPEED;
		} else {
			speed = SPEED;
		}
		_pos.y += SPEED;// /3.0f;
		// _hexCoords.w += speed;
	}

	public void moveDown() {
		float speed;
		if (CREEP) {
			speed = CREEP_SPEED;
		} else {
			speed = SPEED;
		}
		_pos.y -= SPEED;// /3.0f;
		// _hexCoords.w -= speed;
	}
}
